<%-- 
    Document   : order
    Created on : Mar 27, 2013, 5:52:54 PM
    Author     : Shaun McCready
--%>
<%@page import="org.domain.Item"%>
<%@page import="org.domain.Customer"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />

  <title>Order</title>
  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
  <script type="text/javascript" src=
  "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
    <script type="text/javascript" src="js/ajax.js"></script>
  <script type="text/javascript">
//<![CDATA[
  function getParameterByName(name)
  {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  var itemname = getParameterByName('itemname');
  $(document).ready(function(){
        $('#nav li').hover(function () {
                $(this).find('.dropDown').slideToggle(200);
                $(this).toggleClass('active');
  });

                   $('#itemC').val(itemname);

        });

  //]]>
  </script>
</head>

<body>
    <div class="wrapper">
        <div id="navContainer">
            <ul class="clear" id="nav">
                <li class="first"><a class="active" href="home.jsp">Home</a></li>

                <li>
                    <a href="camera.jsp">Products</a>

                    <div class="dropDown">
                        <div class="top"></div>

                        <div class="items">
                            <ul>
                                <li class="first"><a href="camera.jsp">Cameras</a></li>

                                <li><a href="dvd.jsp">DVD Players</a></li>

                                <li class="last"><a href="tv.jsp">Televisions</a></li>
                            </ul>
                        </div>
                    </div>
                </li>
                    
                <li><a  class="selected href="order.jsp">Order</a></li>

                <li><a href="payment.jsp">Payment</a></li>

                <li class="last"><a href="logout">Logout</a></li>
            </ul>
        </div>
  </div>
<div class="shoppingcart" style="position:absolute; top:11px; right:25%; margin-right:0px;">
    <%
    String cart1 = request.getSession().getAttribute("cart").toString();
    int cart = Integer.parseInt(cart1);
    %>
    <img src="images/cart.png" width="30" height="30" />

    <span style="padding:0; color:silver;" id="cart">Items:<span id="newcart" class="newItemGlow1"> <%=cart%></span></span>

</div>
  <div id="mainContent">
    <h1>Order Entry</h1>
    <br/>
    

        <%

     int[] orderItems = (int[])request.getSession().getAttribute("orderItems");
     Customer cust = (Customer)request.getSession().getAttribute("cust");

     //if(orderItems == null)
     if(orderItems == null)
      {
    %>

<p>There currently is nothing on order.</p>

<%
    }
     else
         {

         //Customer cust = (Customer)request.getSession().getAttribute("cust");
%>

<p>Billing and Shipping Address</p>

 <form action="orderProcessing" method="POST" class="aligned">
        
        <table style="border-spacing: 5px 10px;">
            
            <tr>
                <td><label for="countryb">Country</label></td>
                <td><input size="35" type="text" name="countryb" required/></td>
                <td><label for="provinceb">Province</label></td>
                <td><input size="35" type="text" name="provinceb" required/></td>
            </tr>
            <tr>
                <td><label for="firstb">Full Name</label></td>
                <td><input size="35" type="text" name="nameb" required/></td>
                <td><label for="lastb">Customer Reference Number</label></td>
                <td><input size="35" type="text" name="custRefNumb" required/></td>
            </tr>
            <tr>
                <td><label for="add1b">Address 1</label></td>
                <td><input size="35" type="text" name="add1b" required/></td>
                <td><label for="add2b">Address 2</label></td>
                <td><input size="35" type="text" name="add2b"/></td>
            </tr>
            <tr>
                <td><label for="cityb">City</label></td>
                <td><input size="35" type="text" name="cityb" required/></td>
                <td><label for="postb">Postal Code</label></td>
                <td><input size="35" type="text" name="postb" required/></td>
            </tr>
            <tr>
                <td><label for="email">Email Address</label></td>
                <td><input size="35" type="email " name="email" required/></td>
                <td><label for="phone">Phone Number</label></td>
                <td><input size="35" type="tel" name="phone" required/></td>
            </tr>
            <!--
            <tr>
                <td><label for="notes">Order Notes</label><br /></td>
            </tr>
            -->
       </table>
           <!-- <textarea style="margin-left:15px;" id="notes" rows="4" cols="50"></textarea> -->


        <!--Retrieve all items and loop through and display -->
      <br/>
      <br/>
      <hr/>
      <br/>

      <table>
          <tr>
              <th>Item</th>
              <th>Manufacturer</th>
              <th>Quantity</th>
              <th>Cost</th>
          </tr>
       <div id="orderItems">
           <%
           
           ArrayList<Item> list = (ArrayList<Item>)request.getSession().getAttribute("inventory");

           for(int i=0; i < orderItems.length; i++)
               {
               if(orderItems[i] > 0)
                   {
           %>
           <tr id="itemrow<%=i%>">
               <td><%=list.get(i).getProduct() %></td>
               <td><%=list.get(i).getManufacturer() %></td>
               <td><input name="qty<%=i%>" id="qty<%=i%>" value="<%=orderItems[i] %>" style="width:45%;"></input></td>
               <td><%=list.get(i).getPrice()%></td>
               <td><button id="update" type="button" style="margin:0px; padding:0px;" onclick="updateCart(<%=i%>)">Update</button></td>
               <td><button id="remove" type="button" style="margin:0px; padding:0px;" onclick="removeCart(<%=i%> ,0)">Remove</button></td>
           </tr>

            <%
                    }
               }
           %>
       </div>
   <!--
       <tr>
           <td>Example</td>
           <td><input size="10" maxlength="3" type="tel" id="qty" value="1" /></td>
           <td>$99.99</td>
           <td><button id="update" type="button" style="margin:0px; padding:0px;">Update</button></td>
           <td><button id="remove" type="button" style="margin:0px; padding:0px;">Remove</button></td>
       </tr>
-->
       <tr><td><button type="submit" style="margin:0px; padding:0px;">Submit Order</button></td></tr>
   </table>
	    </form>
  <%
  }
     %>
  </div>

  <div id="footer">
    <center>
 <a href="home.jsp">Home</a> | <a href="camera.jsp">Products</a> | <a href="order.jsp">Order</a> | <a href=
      "payment.jsp">Payment</a> | <a href="logout">Logout</a><br />
      Copyright 2013 by Company X. All Rights Reserved.
    </center>
  </div>
</body>
</html>